function checkFile(obj,type){
	var reg = eval('/.('+type+')$/g');
	if(obj.value.toLowerCase().match(type)==null){
		reg=type.replace(/\|/g," \/ ")
		alert('请上传 '+reg+' 文件');
		try{
			obj.outerHTML+=''
		}catch(e){
			obj.value='';
		}
	}
}

function fill(who,value,add){
	if(add==1){
		if(getid(who).value.indexOf(value)==-1){
			value = $('#'+who).val() + value;
			$('#'+who).val(value);
		}
		else{
			alert('已存在输入框中');
		}
	}else{
		$('#'+who).val(value);
	}
}

function fillcando(who){
	
	if (who == null){
		who = 'user';
	}
	
	var obj = getid(who + who + '1');
	if (obj.options[obj.selectedIndex].value!=''){
		var v1 = obj.options[obj.selectedIndex].value;
	}else{
		var v1 = obj.options[obj.selectedIndex].innerText;
	}
	
	if (v1 == '请选择'){
		v1='';
	}
	
	if (v1 != ''){
		
		var v = v1;

		var obj = getid(who + who + '2');
		if (obj != null){
			if (obj.options[obj.selectedIndex].value!=''){
				var v2 = obj.options[obj.selectedIndex].value;
			}else{
				var v2 = obj.options[obj.selectedIndex].innerText;
			}
			
			if (v2 != '请选择'){
				v += ',' + v2;
			}
		}

		fill('cando', v + '\r\n', 1);
	}
}

function add(){
	var s = confirm("真的要再次添加吗?");
	if(s){
		getid('id').value = '';
		getid('form').submit();
	}
}

var u = window.location.href;
function sortlist(id){
	data['id'] = document.getElementById('id').value;
	var obj = $('#'+id);
	var lv = obj.attr('level');
	var tabel = obj.attr('sort_table');
	var fid = lv==0?lv:obj.val();
	var sname = lv==0?id:obj.attr('sname');
	var p = !obj.attr('p')?'sort':obj.attr('p');
	
	if(data['id']=='' || data['id']==null){
		try{var check = u.split(sname+String(parseInt(lv)+1)+'/')[1].split('/')[0];}
		catch(e){}
	}else{
		var check = data[sname+String(parseInt(lv)+1)];
	}
	var url = '/adminiii.php/'+p+'/aj_sort';
	url += '/s/'+tabel;
	url += '/lv/'+lv;
	url += '/fid/'+fid;
	url += '/sname/'+sname;
	url += '/check/'+check;
	url += "/rd/" + Math.random();
	
	clean(lv);
	
	$.get(url,function(txt){
		if(txt!=null){
			if(lv==0){
				obj.css('display','none');
			}
			obj.after(txt);
			if(check!=null){
				sortlist(sname+String(parseInt(lv)+1));
			}
		}
		
	});
	
	function clean(lvv){
		if(document.getElementById(sname+String(++lvv))){
			$('#'+sname+String(lvv)).remove();
			clean(lvv);
		}
	}
}

// FireFox innerText 支持
try{
        HTMLElement.prototype.__defineGetter__
        (
        "innerText",
        function ()
        {
            var anyString = "";
            var childS = this.childNodes;
            for(var i=0; i<childS.length; i++)
            {
                if(childS[i].nodeType==1)
                    anyString += childS[i].tagName=="BR" ? '"n' : childS[i].innerText;
                else if(childS[i].nodeType==3)
                    anyString += childS[i].nodeValue;
            }
            return anyString;
        }
    ); 
}
catch(e){}